/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package muddb.entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;


/**
 *
 * @author keith
 */
@Entity
@Table( name = "skill_prof" )
@NamedQueries(
  {
    @NamedQuery( name = "SkillProf.findByUserId",
                  query = "SELECT s FROM SkillProf s WHERE s.userId = :userId" ),
    @NamedQuery( name = "SkillProf.findByCharId",
                  query = "SELECT s FROM SkillProf s WHERE s.charId = :charId" ),
    @NamedQuery( name = "SkillProf.findBySkillId",
                  query = "SELECT s FROM SkillProf s WHERE s.skillId = :skillId" ),
    @NamedQuery( name = "SkillProf.findByProf",
                  query = "SELECT s FROM SkillProf s WHERE s.prof = :prof" ) } )
@IdClass( SkillProfPK.class )
public class SkillProf implements Serializable {
  private static final long serialVersionUID = 1L;
  private int userId;
  private int charId;
  private int skillId;
  private int skillGroupId;
  private Short prof;
  private Skill skill;
  private UserChar userChar;


  public SkillProf() {
  }


  public SkillProf( int userId, int charId, int skillGroupId, int skillId ) {
    this.userId = userId;
    this.charId = charId;
    this.skillGroupId = skillGroupId;
    this.skillId = skillId;
  }


  @Id
  @Column( name = "user_id", nullable = false )
  public int getUserId() {
    return userId;
  }

  public void setUserId(int userId) {
    this.userId = userId;
  }


  @Id
  @Column(name = "char_id", nullable = false)
  public int getCharId() {
    return charId;
  }

  public void setCharId(int charId) {
    this.charId = charId;
  }

  @Id
  @Column(name = "skill_id", nullable = false)
  public int getSkillId() {
    return skillId;
  }

  public void setSkillId(int skillId) {
    this.skillId = skillId;
  }

  @Id
  @Column(name = "skill_grp_id", nullable = false)
  public int getSkillGroupId() {
    return skillGroupId;
  }


  public void setSkillGroupId( int skillGroupId ) {
    this.skillGroupId = skillGroupId;
  }

  @Column(name = "prof")
  public Short getProf() {
    return prof;
  }


  public void setProf( Short prof ) {
    this.prof = prof;
  }


  @Id
  @JoinColumns( 
    {
      @JoinColumn( name = "skill_grp_id", referencedColumnName = "skill_grp_id",
                    nullable = false),
      @JoinColumn( name = "skill_id", referencedColumnName = "skill_id",
                    insertable = false, updatable = false)})
  @ManyToOne
  public Skill getSkill() {
    return skill;
  }


  public void setSkill( Skill skill ) {
    this.skill = skill;
  }


  @JoinColumns(
    {
      @JoinColumn( name = "user_id", referencedColumnName = "user_id",
                    insertable = false, updatable = false),
      @JoinColumn(name = "char_id", referencedColumnName = "char_id",
                    insertable = false, updatable = false)})
  @ManyToOne
  public UserChar getUserChar() {
    return userChar;
  }


  public void setUserChar( UserChar userChar ) {
    this.userChar = userChar;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) userId;
    hash += (int) charId;
    hash += (int) skillId;
    hash += (int) skillGroupId;
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if ( !( object instanceof SkillProf ) ) {
      return false;
    }
    SkillProf other = (SkillProf) object;
    if ( this.userId != other.userId ) {
      return false;
    }
    if ( this.charId != other.charId ) {
      return false;
    }
    if ( this.skillId != other.skillId ) {
      return false;
    }
    if ( this.skillGroupId != other.skillGroupId ) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "muddb.entities.SkillProf[userId=" + userId + ", charId=" + charId + ", skillGroupId=" + skillGroupId +  ", skillId=" + skillId + "]";
  }

}
